import requests
import base64
def timecatch():
    try:
        hea = {'User-Agent': 'Mozilla/5.0'}
        url = r'http://time1909.beijing-time.org/time.asp'
        r = requests.get(url=url,headers=hea)
        if r.status_code == 200:
            beijin=r.text.split(";")
            year=beijin[1].split("=")[1]
            month=beijin[2].split("=")[1]
            day=beijin[3].split("=")[1]
            hour=beijin[5].split("=")[1]
            if(len(hour)==1):
                hour="0"+str(hour)
            mins=beijin[6].split("=")[1]
            if(len(mins)==1):
                mins="0"+str(mins)
            sec=beijin[7].split("=")[1]
            if(len(sec)==1):
                sec="0"+str(sec)
            rq="%s/%s/%s"%(year,month,day)
            sj="%s:%s:%s"%(hour,mins,sec)
            return rq,sj
    except:
        print("获取在线时间失败，请检查电脑是否联网")
        input("点击换行继续...")
        quit()

'''
zzsj="key{{MDVlZTdmZmIwMTI2ZDAyZDM4MDFhNDIwNGQzN2FmNzBjN2RhMmU0NGVmZGI3NzQyZjZjZGJlNTdhNzJmOThkNmQyOWViNDRlNGY5ODYzMzdmNTY1NDRjYjFiOTM5MjZkN2U2MWFiZDgyYjBjOTZhNWJkZWIwODQ3OTlkYzE5NWM3NTllMTQ1ZDRjMDhmMjZmZjkwNzYwZTU1ZDA3ODM2NTM0MzkxYzQ0NmIzZTlkODQ5YmZmZDlmNmU0OGQ1YmU4MTZlZTFiY2U4OTkzZGY3YmUzNmQwZTgyNGQ3MDE0ZDdmZjIxZjA3YmI4NTY5YWVhOWNkOGEzYWJmOTI1NDk2MDljNHgw}"
zzsj=base64.b64decode(zzsj[4:][:-1].replace("{","=")[::-1]).decode("UTF-8")).encode("UTF-8")[::-1]
print(zzsj)
'''

riqi,shijian=timecatch()
riqi=riqi.split("/")
shijian=shijian.split(":")
xzsj=[riqi[0],riqi[1],riqi[2],shijian[0],shijian[1],shijian[2]]
a,b,c,d,e,f=input("请输入到期时间(例如:2020 9 24 20 00 00):").split(" ")
dqsj=[a,b,c,d,e,f]
for i in range(len(xzsj)):
    if(len(xzsj[i])==1):
        xzsj[i]="0"+xzsj[i]
for i in range(len(xzsj)):
    if(len(dqsj[i])==1):
        dqsj[i]="0"+dqsj[i]
xzsj=''.join(xzsj).strip(" ")
dqsj=''.join(dqsj).strip(" ")
jmsj=""
for i in xzsj:
    for j in dqsj:
        jmsj+=str(i)+str(j)
#DDD=str(hex(int(str(jmsj)[::-1])))[::-1].encode("UTF-8")
jmsj=base64.b64encode(str(hex(int(str(jmsj)[::-1])))[::-1].encode("UTF-8")).decode("UTF-8")[::-1].replace("=","{")
#反过来(base64(反过来(字符串(十六进制(十进制(反过来的jmsj)))).UTF-8加密)UTF-8解密).替换=变{
#先把头尾删了,然后重置=
#反过来的数据base64解密
#解密的内容是把16进制反过来转成10进制然后反过来并且DECODE
#把内容ENCODE为UTF-8
zzsj="key{"+jmsj+"}"
print("=================================================\n")
print(zzsj)
print("\n=================================================")
####################
#解密
zzsj=zzsj[3:-1].replace("{","=")
zzsj=base64.b64decode(zzsj[::-1].encode("UTF-8")).decode("UTF-8")
zzsj=str(int(zzsj[::-1].replace("{","="),16))[::-1]

kssj=""
gqsj=""
for i in range(0,len(zzsj),28):
    kssj+=str(zzsj[i])
for i in range(1,28,2):
    gqsj+=str(zzsj[i])


kssj=list(kssj)
fh=["\\","\\"," ",":",":"]
k=0
for i in range(4,len(kssj)+3,3):
    kssj.insert(i,fh[k])
    k+=1
print("开始时间:"+"".join(kssj))


k=0
gqsj=list(gqsj)
fh=["\\","\\"," ",":",":"]
for i in range(4,17,3):
    gqsj.insert(i,fh[k])
    k+=1
print("过期时间:"+"".join(gqsj))


'''

#dqsj=""
#xzsj=""
#jmsj=jmsj[::-1]
#for i in jmsj:
#   for j in jmsj:
#       jiemi=i+j

print(zzsj)


#zzsj=zzsj[4:][:-1].replace("=","{")
'''
